home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / DTS QT Utilities.May-95 / Projects & Test Apps / QT Internals / QTInternals.c < prev    next >
Encoding:
Text File  |  1995-04-30  |  13.2 KB  |  399 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        QTInternals.c
  3.  
  4.     Contains:    Functions dealing with dumping internal movie information.
  5.  
  6.     Written by:    DTS
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.        <1>         1/4/95    khs        first file
  13.        
  14. */
  15.  
  16.  
  17. // INCLUDES
  18. #include "QTInternals.h"
  19. #include "DTSQTUtilities.h"
  20.  
  21.  
  22. // ______________________________________________________________________
  23. // FUNCTIONS
  24.  
  25.  
  26.  
  27. // ______________________________________________________________________
  28. void ShowGlobalMovieInfo(Movie theMovie)
  29. {
  30.     Str255     tmpStr;
  31.     TimeValue    tv, ts;
  32.     Fixed mr;
  33.     
  34.     DebugAssert(aMovie != NULL);
  35.     
  36.     GetWTitle(FrontWindow(), tmpStr);
  37.     printf("\nGlobal System Information for %s:\n", p2cstr(tmpStr));
  38.  
  39.     // Memory related information.
  40.     printf("This movie allocates %ld bytes in the current application heap.\n",
  41.         QTUCalculateMovieMemorySize(theMovie));
  42.     printf("Note that any possible associated movie controllers take each 10k or so.\n\n");
  43.     
  44.     // Global Time Information
  45.     ts = GetMovieTimeScale(theMovie);
  46.     tv = GetMovieDuration(theMovie);
  47.     printf("The time scale for this movie is %ld.\n", ts);
  48.     printf("The movie duration (TimeValue) = %ld\n", tv);
  49.     printf("The movie duration in seconds = %7.2f\n", (float)  tv / ts);
  50.     
  51.     printf("The current movie position (in seconds) = %7.2f\n", (float) GetMovieTime(theMovie, NULL) / ts);
  52.  
  53.     mr = GetMovieRate(theMovie);
  54.     printf("The current movie rate is %7.2f  (0 means movie is not running, < 0 going backwards).\n",  (float) mr /fixed1);
  55. }
  56.  
  57.  
  58. // ______________________________________________________________________
  59. void ShowMovieTrackInfo(Movie theMovie)
  60. {
  61.     OSErr                    anErr  = noErr;
  62.     long                        aTrackCount, index;
  63.     Track                    aTrack;
  64.     long                        aTrackUsage;
  65.     Str255                    tmpStr;
  66.     Fixed                    height, width;
  67.     short                    trackVol;
  68.     MatrixRecord        mr;
  69.     long                        nVideoTracks = 0;
  70.     long                        nSoundTracks = 0;
  71.     long                        nTextTracks = 0;
  72.     long                        nMusicTracks = 0;
  73.     
  74.     GetWTitle(FrontWindow(), tmpStr);
  75.     printf("\nTrack Information for %s:\n", p2cstr(tmpStr));
  76.     
  77.     // TRACK COUNT
  78.     aTrackCount = GetMovieTrackCount(theMovie);
  79.     anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  80.     if(anErr != noErr) return;
  81.     
  82.     if(aTrackCount == 0) 
  83.     {
  84.         printf("The Movie has no tracks.\n");
  85.         return;
  86.     }
  87.     else
  88.         printf("The Movie has %d track(s).\n", aTrackCount);
  89.  
  90.     // Parse through each track and get more information:
  91.     for(index = 1; index <= aTrackCount; index++)
  92.     {
  93.         OSType aTrackType;
  94.         Media aMedia;
  95.         
  96.         printf("\n");
  97.         
  98.         aTrack = GetMovieIndTrack(theMovie, index);
  99.         
  100.         // TRACK TYPE
  101.         aMedia = GetTrackMedia(aTrack);
  102.         GetMediaHandlerDescription(aMedia, &aTrackType, 0, 0);
  103.         
  104.         switch (aTrackType)
  105.         {
  106.             case SoundMediaType: printf("This is a sound track.\n"); 
  107.                 nSoundTracks++;
  108.                 break;
  109.                 
  110.             case VideoMediaType: printf("This is a video track.\n"); 
  111.                 nVideoTracks++;
  112.                 break;
  113.                 
  114.             case TextMediaType: printf("This is a text track.\n"); 
  115.                 nTextTracks++;
  116.                 break;
  117.                 
  118.             case MPEGMediaType: printf("This is an MPEG track.\n"); 
  119.                 break;
  120.                 
  121.             case MusicMediaType: printf("This is a music track.\n"); 
  122.                 nMusicTracks++;
  123.                 break;
  124.                 
  125.             case TimeCodeMediaType: printf("This is a time code track.\n"); 
  126.                 break;
  127.                 
  128.             default: 
  129.             {
  130.                 Byte *bp = (Byte *)&aTrackType;
  131.                 printf("The track is of type '%c%c%c%c' format.\n", bp[0], bp[1], bp[2], bp[3]);
  132.                 break;
  133.             }
  134.         }
  135.         
  136.         // TRACK ID
  137.         printf("Track ID: %d\n", GetTrackID(aTrack));
  138.     
  139.         // TRACK ENABLED
  140.         if(GetTrackEnabled(aTrack))
  141.             printf("Track is enabled.\n");
  142.         else
  143.             printf("Track is disabled.\n");
  144.         
  145.         // TRACK LAYER
  146.         printf("Track Layer: %d\n", GetTrackLayer(aTrack));
  147.         
  148.         // TRACK USAGE
  149.         aTrackUsage = GetTrackUsage(aTrack);
  150.         if(aTrackUsage & trackUsageInMovie)
  151.             printf("Track is used in Movie.\n");
  152.         if(aTrackUsage & trackUsageInPreview)
  153.             printf("Track is used in a preview.\n");
  154.         if(aTrackUsage & trackUsageInPoster)
  155.             printf("Track is used in a poster.\n");
  156.     
  157.         // TRACK DURATION
  158.         printf("Duration of the track = %ld\n", GetTrackDuration(aTrack));
  159.         
  160.         // TRACK DIMENSIONS
  161.         GetTrackDimensions(aTrack, &width, &height);
  162.         printf("Track width = %ld, Track height = %ld\n", Fix2Long(width), Fix2Long(height));
  163.         
  164.         // TRACK MATRIX
  165.         GetTrackMatrix(aTrack, &mr);
  166.         
  167.         printf("Matrix record, row 0 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[0,0]), 
  168.                                 Fix2Long(*mr.matrix[0,1]), Fix2Long(*mr.matrix[0,2]));
  169.         printf("Matrix record, row 1 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[1,0]), 
  170.                                 Fix2Long(*mr.matrix[1,1]), Fix2Long(*mr.matrix[1,2]));
  171.         printf("Matrix record, row 2 = [%ld], [%ld], [%ld]\n", Fix2Long(*mr.matrix[2,0]), 
  172.                                 Fix2Long(*mr.matrix[2,1]), Fix2Long(*mr.matrix[2,2]));
  173.         
  174.         // TRACK VOLUME
  175.         trackVol = GetTrackVolume(aTrack);
  176.         if(trackVol == 255)
  177.             printf("Track Volume is 1.0\n");
  178.         else
  179.             printf("Track Volume = %d.%d\n", (signed short)(trackVol >> 8) , (trackVol & 0xFF));
  180.     }
  181.     
  182.     // Check how many similar tracks, if too many of same warn (crossplatform issues)
  183.     if(nVideoTracks > 1)
  184.         printf("NOTE! You have more than one video track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nVideoTracks);
  185.  
  186.     if(nSoundTracks > 1)
  187.         printf("NOTE! You have more than one sound track (%ld tracks), you need to enable just one at a time under QuickTime for Windows (2.0.1 forward).\n", nSoundTracks);
  188.  
  189.     if(nTextTracks > 1)
  190.         printf("NOTE! You have more than one text track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nTextTracks);
  191.  
  192.     if(nMusicTracks > 1)
  193.         printf("NOTE! You have more than one music track (%ld tracks), this will be a problem with QuickTime for Windows.\n", nMusicTracks);
  194. }
  195.  
  196.  
  197. // ______________________________________________________________________
  198. void ShowMovieVideoInfo(Movie theMovie)
  199. {
  200.     OSErr        anErr = noErr;
  201.     Str255     tmpStr;
  202.     short        trackCount, index;
  203.     long            nSamples;
  204.     float            nSeconds;
  205.  
  206.     DebugAssert(aMovie != NULL);
  207.     
  208.     GetWTitle(FrontWindow(), tmpStr);
  209.     printf("\nVideo Media Information for %s:\n", p2cstr(tmpStr));
  210.  
  211.     // VIDEO FRAMES/SAMPLES
  212.     nSamples = QTUCountMediaSamples(theMovie, VideoMediaType);
  213.     printf("The movie has %ld video frames (samples) ", nSamples);
  214.     printf("of which %ld are key frames\n", QTUCountKeySamples(theMovie, VideoMediaType) );
  215.  
  216.     printf("The duration of the first video sample is %ld\n", QTUGetDurationOfFirstMovieSample(theMovie, VideoMediaType));
  217.     
  218.     nSeconds =     GetMovieDuration(theMovie)/ GetMovieTimeScale(theMovie);
  219.     printf("Frames per second (assuming that each video sample is of the same length) = %7.2f  fps\n", (float) nSamples/nSeconds );
  220.     
  221.     // Get the Image Description Structure and present the values.
  222.     trackCount = GetMovieTrackCount(theMovie);
  223.     
  224.     for(index = 1; index <= trackCount; index++)
  225.     {
  226.         Track        aTrack = NULL;
  227.         Media        aMedia = NULL;
  228.         OSType        aMediaType;
  229.         
  230.         aTrack = GetMovieIndTrack(theMovie, index); DebugAssert(aTrack != NULL);
  231.         aMedia = GetTrackMedia(aTrack); DebugAssert(aMedia != NULL);
  232.         anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  233.         if(anErr != noErr)
  234.         {
  235.             printf("Problems with getting trackmedia = %d\n", anErr);
  236.             return;
  237.         }
  238.  
  239.         GetMediaHandlerDescription(aMedia, &aMediaType, 0, 0);
  240.         if(aMediaType == VideoMediaType) // We just want to check the video media samples.
  241.         {
  242.             SampleDescriptionHandle anImageDesc = NULL;
  243.             anImageDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription));
  244.             DebugAssert(GetMemErr == noErr);
  245.  
  246.             GetMediaSampleDescription(aMedia, 1, anImageDesc);
  247.             anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  248.             MoveHHi((Handle)anImageDesc); HLock((Handle)anImageDesc); // Really would not need to, but printf (don't trust that one
  249.                                                                                                           // due to the MetroWerks Sioux environment).
  250.             if(anErr != noErr)
  251.             {
  252.                 DisposeHandle((Handle)anImageDesc);
  253.                 continue;
  254.             }
  255.  
  256.             // OK, we have the Image Description, now present the values (see IM:QuickTime, page 3-50 for more
  257.             // information about the ImageDescription structure).
  258.             
  259.             printf("The video track has a pixel depth of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->depth);
  260.     
  261.             // Get the image description height and width values, test if these are multiple of 4 (if not there's a performance penalty).
  262.             {
  263.             long rest;
  264.             
  265.             printf("The video track has a source image height of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->height);
  266.         
  267.             rest  = (*(ImageDescriptionHandle)anImageDesc)->height % 4;
  268.             if (rest != 0)
  269.                 printf("NOTE! The source image height is not a multiple of 4, this means a performance hit.\n");
  270.  
  271.             printf("The video track has a source image width of %d.\n", (*(ImageDescriptionHandle)anImageDesc)->width);
  272.             
  273.             rest  = (*(ImageDescriptionHandle)anImageDesc)->width % 4;
  274.             if (rest != 0)
  275.                 printf("NOTE! The source image width is not a multiple of 4, this means a performance hit.\n");
  276.             }
  277.             
  278.             printf("The video track has a horizontal resolution of %ld.\n", Fix2Long( (*(ImageDescriptionHandle)anImageDesc)->hRes) );
  279.             printf("The video track has a vertical resolution of %ld.\n", Fix2Long( (*(ImageDescriptionHandle)anImageDesc)->vRes) );
  280.             
  281.             printf("The codec used to compress the video samples:  %s\n", p2cstr( (*(ImageDescriptionHandle)anImageDesc)->name) );
  282.             printf("Note that this is the codec for the first video sample, the video samples in the movie might have various codecs used...\n");
  283.             {
  284.                 Byte *bp = (Byte *)&(*(ImageDescriptionHandle)anImageDesc)->vendor;
  285.                 printf("The video track was compressed by codec provided by '%c%c%c%c'.\n", bp[0], bp[1], bp[2], bp[3]);
  286.             }
  287.             printf("The temporal compression setting is %ld\n",  (*(ImageDescriptionHandle)anImageDesc)->temporalQuality);
  288.             printf("The spatial compression setting is %ld\n",  (*(ImageDescriptionHandle)anImageDesc)->spatialQuality);
  289.             
  290.             
  291.             printf("The image description structure is %ld bytes in size.\n", 
  292.                             (*(ImageDescriptionHandle)anImageDesc)->idSize);
  293.  
  294.             DisposeHandle((Handle)anImageDesc);
  295.         }
  296.     }
  297. }
  298.  
  299.  
  300. // ______________________________________________________________________
  301. void ShowMovieSoundInfo(Movie theMovie)
  302. {
  303.     Str255     tmpStr;
  304.     short        trackCount, index;
  305.     OSErr        anErr = noErr;
  306.     
  307.     DebugAssert(aMovie != NULL);
  308.     
  309.     GetWTitle(FrontWindow(), tmpStr);
  310.     printf("\nSound Media Information for %s:\n", p2cstr(tmpStr));
  311.     
  312. #ifdef THIS_WILL_TAKE_LONG
  313.     printf("The movie has %d sound samples (samples)\n", QTUCountMediaSamples(theMovie, SoundMediaType));
  314. #endif // THIS_WILL_TAKE_LONG
  315.  
  316.     // Get the sound description handle and munch it:
  317.     trackCount = GetMovieTrackCount(theMovie);
  318.     
  319.     for(index = 1; index <= trackCount; index++)
  320.     {
  321.         Track        aTrack = NULL;
  322.         Media        aMedia = NULL;
  323.         OSType    aMediaType;
  324.         
  325.         aTrack = GetMovieIndTrack(theMovie, index); DebugAssert(aTrack != NULL);
  326.         aMedia = GetTrackMedia(aTrack); DebugAssert(aMedia != NULL);
  327.         anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  328.         if(anErr != noErr)
  329.         {
  330.             printf("Problems with getting trackmedia = %d\n", anErr);
  331.             return;
  332.         }
  333.         
  334.         GetMediaHandlerDescription(aMedia, &aMediaType, 0, 0);
  335.         if(aMediaType == SoundMediaType)        // We just want to check out the sound description handles.
  336.         {
  337.             SampleDescriptionHandle aDesc = NULL;
  338.             aDesc = (SampleDescriptionHandle)NewHandle(sizeof(SampleDescription)); 
  339.             DebugAssert(GetMemErr() == noErr);
  340.         
  341.             GetMediaSampleDescription(aMedia, 1, aDesc);
  342.             anErr = GetMoviesError(); DebugAssert(anErr == noErr);
  343.             MoveHHi((Handle)aDesc); HLock((Handle)aDesc); // Really would not need to, but printf (don't trust that one
  344.                                                                                      // due to the MetroWerks Sioux environment).
  345.             if(anErr != noErr)
  346.             {
  347.                 DisposeHandle((Handle)aDesc);
  348.                 continue;
  349.             }
  350.             // OK, we have the sound description handle now, present the values
  351.             printf("The sound track rate is %d Hz.\n", (*(SoundDescriptionHandle)aDesc)->sampleRate >> 16);
  352.             {
  353.             long soundRate =  (*(SoundDescriptionHandle)aDesc)->sampleRate >> 16;
  354.             if (soundRate < 30000)
  355.                 if( (soundRate != 22050) && (soundRate != 11025) ) 
  356.                     printf("NOTE! The movie has a sound rate that will maybe cause performance problems with certain PC sound boards. If possible use 22050 or 11025 kHz instead\n");
  357.             }
  358.             
  359.             printf("The sound track size is %d bit.\n", (*(SoundDescriptionHandle)aDesc)->sampleSize);
  360.             
  361.             printf("The sound track has %d channel(s).\n", (*(SoundDescriptionHandle)aDesc)->numChannels);
  362.             {
  363.                 Byte *bp = (Byte *)&(*(SoundDescriptionHandle)aDesc)->dataFormat;
  364.                 printf("The sound track has the '%c%c%c%c' format.\n", bp[0], bp[1], bp[2], bp[3]);
  365.             }
  366.             
  367.             printf("The sound description structure is %ld bytes in size.\n", 
  368.                             (*(SoundDescriptionHandle)aDesc)->descSize);
  369.         }
  370.     }
  371. }
  372.  
  373.  
  374. // ______________________________________________________________________
  375. // This is a variation function of the QTUCountMediaSamples one, we want to figure out how
  376. // many key frames we have in the movie.
  377.  
  378. pascal long QTUCountKeySamples(Movie theMovie, OSType theMediaType)
  379. {
  380.     long numFrames = 0;
  381.     
  382.     short flags = nextTimeEdgeOK + nextTimeSyncSample;
  383.     TimeValue aDuration = 0;
  384.     TimeValue theTime = 0;
  385.     
  386.     GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
  387.     if(theTime == -1) return numFrames;
  388.  
  389.     flags = nextTimeSyncSample; // Don't include the  nudge after the first interesting time.
  390.     
  391.     while(theTime != -1)  // When the returned time equals -1, then there were no more interesting times.
  392.     {
  393.         numFrames++;
  394.         GetMovieNextInterestingTime(theMovie, flags, 1, &theMediaType, theTime, 0, &theTime, &aDuration);
  395.     }
  396.     
  397.     return numFrames;
  398. }
  399.